
package com.wctj.api.web.controller;

import com.wctj.api.base.Result;
import com.wctj.api.business.common.service.DdwxMemberService;
import com.wctj.api.business.soe.service.FuiouPayManagerService;
import com.wctj.api.infra.common.api.DefaultPayMessageHandler;
import com.wctj.api.infra.common.api.PayMessageHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;

/**
 * 发起支付入口
 *
 *
 */
@Deprecated
@RestController
@RequestMapping("fuiou")
public class FuiouPayController {

    @Resource
    private FuiouPayManagerService fuiouPayManagerService;
    @Resource
    private DdwxMemberService ddwxMemberService;

    @GetMapping("test")
    public Result<String> test(@RequestParam("name") String name) {

        return Result.success(name);
    }

    @GetMapping("member")
    public Result member(@RequestParam("id") Long id) {

        return Result.success(ddwxMemberService.findById(id));
    }

    /**
     * 跳到支付页面
     * 针对实时支付
     *
     * @param price       金额
     * @return 跳到支付页面
     */
    @RequestMapping(value = "toPay.html", produces = "text/html;charset=UTF-8")
    public String toPay( BigDecimal price) {
        //TODO 订单ID
        String orderId = "";
        return fuiouPayManagerService.toPay(price,orderId);
    }


    /**
     * 支付回调地址 方式一
     *
     * 方式二，{@link #payBack(HttpServletRequest)} 是属于简化方式， 试用与简单的业务场景
     *
     * @param request 请求
     *
     * @return 是否成功
     * @throws IOException IOException
     * @see #payBack(HttpServletRequest)
     */
    @Deprecated
    @RequestMapping(value = "payBackBefore.json")
    public String payBackBefore(HttpServletRequest request) throws IOException {

        return fuiouPayManagerService.payBackBefore(request);
    }

    /**
     * 支付回调地址
     *
     * @param request 请求
     *
     * @return 是否成功
     *
     * 业务处理在对应的PayMessageHandler里面处理，在哪里设置PayMessageHandler，详情查看{ com.zgzg.shop.pay.common.api.PayService#setPayMessageHandler(com.zgzg.shop.pay.common.api.PayMessageHandler)}
     *
     * 如果未设置 {@link PayMessageHandler} 那么会使用默认的 {@link DefaultPayMessageHandler}
     * @throws IOException IOException
     */
    @Deprecated
    @RequestMapping(value = "payBackOld.json")
    public String payBackOld(HttpServletRequest request) throws IOException {

        return fuiouPayManagerService.payBackOld(request);
    }
    
    /**
     * 支付回调地址
     *
     * @param request 请求
     * @return 是否成功
     * <p>
     * 业务处理在对应的PayMessageHandler里面处理，在哪里设置PayMessageHandler，详情查看 com.zgzg.shop.pay.common.api.PayService#setPayMessageHandler(com.zgzg.shop.pay.common.api.PayMessageHandler)}
     * <p>
     * 如果未设置 {@link PayMessageHandler} 那么会使用默认的 {@link DefaultPayMessageHandler}
     */
    @RequestMapping(value = "payBack.json")
    public String payBack(HttpServletRequest request)  {

        return fuiouPayManagerService.payBack(request);
    }

}
